<template>
  <div>
    <div class="title">
      <p>{{ infoObj.title }}</p>
    </div>
    <div class="author">
      <p>{{ infoObj.author }}</p>
    </div>
    <div class="images">
      <v-touch v-on:doubletap="setCollect()">
        <img :src="infoObj.imgUrl" alt="" />
      </v-touch>
    </div>
    <div class="progress-bar">
      <ul>
        <li>
          <span>00:00</span>
        </li>
        <li>
          <div></div>
          <span></span>
        </li>
        <li>
          <span>06:00</span>
        </li>
      </ul>
    </div>
    <div class="action-bar">
      <ul>
        <li>
          <span class="iconfont icon-cycle"></span>
        </li>
        <li>
          <span class="iconfont icon-left-play"></span>
          <div @click="myPlay">
            <span 
            :class="[iconfont ,cla == 0 ? iconPlay : iconPause]"></span>
          </div>
          <span class="iconfont icon-right-play"></span>
        </li>
        <li>
          <span class="iconfont icon-list"></span>
        </li>
      </ul>
    </div>

    <div class="player-box">
      <audio
        loop
        ref="audio"
        :src="`https://wsaudiobssdlbig.yun.kugou.com/202111081327/3d19395939fe88b338a1407593d3e945/bss/extname/wsaudio/dd082f3940cb072ad7c4b229688bc41c.mp3`"
      ></audio>
    </div>

    <div class="success" v-if="flag">
      <p>收藏成功</p>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    infoObj: {
      type: Object,
    },
  },
  data() {
    return {
      flag: false,
      iconfont:"iconfont",
      iconPlay:"icon-play",
      iconPause:"icon-pause",
      cla: 0,
      plays: false,
    };
  },
  name: "Play",
  methods: {
    setCollect() {
      let dataArr = JSON.parse(localStorage.getItem("dataArr"))
      dataArr.push(this.infoObj)
      for(let i = 0; i < dataArr.length; i++){
        for(let j = i+1; j < dataArr.length; j++){
          if(dataArr[i].title == dataArr[j].title){
            dataArr.splice(j,1);
            j--;
          }
        }
      };
      localStorage.setItem("dataArr", JSON.stringify(dataArr))
      this.flag = true;
      setTimeout(() => {
        this.flag = false;
      }, 800);
    },
    myPlay() {
      if (this.$refs["audio"]) {
        if(this.plays == false){
            this.plays = true;
            this.$refs["audio"].play();
            this.cla = 1;
        }else if(this.plays == true){
            this.plays = false;
            this.$refs["audio"].pause();
            this.cla = 0;
        }
      }
    }
  },
};
</script>

<style lang="scss" scoped>
$color: #dc912c;
.title {
  margin: 30px 0 12px 0;
  p {
    text-align: center;
    font-size: 20px;
  }
}
.author {
  margin-bottom: 20px;
  p {
    text-align: center;
    font-size: 16px;
    color: #888;
  }
}
.images {
  width: 340px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  img {
    width: 280px;
    border: 12px solid #ddd;
    border-radius: 6px;
  }
}
.action-bar {
  display: flex;
  justify-content: center;
  padding-top: 24px;
  ul {
    width: 340px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    li {
      span {
        font-size: 24px;
        color: #999;
      }
    }
    li:nth-child(2) {
      span {
        font-size: 24px;
        color: #ccc;
      }
      div:nth-child(2) {
        width: 54px;
        height: 54px;
        display: inline-block;
        border: 1px solid #999;
        border-radius: 50%;
        span{
            display: block;
            padding: 0;
            color: $color;
            text-align: center;
            line-height: 54px;
            font-size: 26px;
        }
      }
      span:nth-child(1) {
        padding: 0 30px 0 16px;
      }
      span:nth-child(3) {
        padding: 0 16px 0 30px;
      }
    }
  }
}
.progress-bar {
  margin-top: 20px;
  ul {
    width: 340px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    li {
      span {
        font-size: 14px;
        color: #999;
      }
    }
    li:nth-child(2) {
      position: relative;
      display: flex;
      align-items: center;
      padding-top: 10px;
      div {
        width: 220px;
        border-bottom: 1px solid #ccc;
      }
      span {
        display: inline-block;
        width: 10px;
        height: 10px;
        background: $color;
        border-radius: 50%;
        position: absolute;
        z-index: 999;
      }
    }
  }
}
.success {
  background: #fffaf0;
  width: 110px;
  height: 60px;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -60px;
  margin-left: -55px;
  border-radius: 5px;
  p {
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    line-height: 60px;
    color: #cc9999;
  }
}
</style>